# ICEMGenerator - 高效的ICEM CFD网格划分Replay Script生成工具
# 案例说明：创建底壁加装了肋片的容器

import os
from ICEMGenerator import create_rectangle, create_cubic, Part, Block, replay_all, init_all_Id

init_all_Id(0)

# 定义肋片和容器尺寸
count = 10  #肋片数量
bold = 0.003  #肋片厚度
interval = 0.1 / count - bold  #肋片间隔
fins_length = bold * count + interval * (count + 1)
Bold = 0.002  #容器厚度

# 创建几何对象
# (1)绘制容器的外长方体
tank = create_cubic(-Bold, fins_length + Bold, -Bold, 0.06 + Bold, -Bold, 0.03, name = 'TANK')
# (2)使用容器的内长方体（底部镂空）切割外长方体
tank_inside = create_cubic(0, fins_length, 0, 0.06, 0, 0.03, back_filled = False, name = 'tank_inside')
tank.join(tank_inside)
# (3)创建肋片（底面镂空）和肋片之间的凹面
fins = [None] * count
concaves = [None] * (count + 1)
concaves[0] = create_rectangle(0, interval, 0, 0.06, 0, axis = 'z', name = 'concave0')
for i in range(count):
    x0 = interval + i * 0.1 / count  #肋片背面的x坐标
    x1 = x0 + bold  #肋片正面的x坐标
    x2 = x1 + interval  #下一个肋片背面的x坐标
    fins[i] = create_cubic(x0, x1, 0, 0.06, 0, 0.02, back_filled = False, name = 'fin%d' % i)
    concaves[i+1] = create_rectangle(x1, x2, 0, 0.06, 0, axis = 'z', name = 'concave%d' % (i + 1))
tank.addSurface(concaves)
tank.join(fins)
tank.setAsFinal()

# 给定边界条件
solid = Part((tank,), 'SOLID', 'SOLID')
wall = Part.wallFromRemainSurfaces()

# 创建块
TANKF = Block(parts_inside = (solid,), parts_boundary = (wall,), name = 'TANKF', dimension = 3, max_element_size = 0.001)

# 一键输出Replay Script
f = open('tank_with_fins.rpl', 'w')
f.write(replay_all('E:/python/ICEMGenerator/demo/tank_with_fins', 'tankf'))
f.close()
os.system('notepad tank_with_fins.rpl')